{include file="public/nheader" /}
<div class="layui-fluid">
    <div class="layui-card">
        <!-- // 默认操作按钮 -->
        <div class="layui-card-header layadmin-card-header-auto ">
            <div class="layui-form">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <div class="layui-input-inline ">
                            <select name="status" lay-search>
                                <option value="">搜已回复</option>
                                <option value="1" {if !empty(input('get.status')) &&
                                    input('get.status')==1}selected{/if}>
                                    未回复</option>
                                <option value="2" {if !empty(input('get.status')) &&
                                    input('get.status')==2}selected{/if}>
                                    已回复</option>
                            </select>
                        </div>
                        <div class="layui-input-inline ">
                            <select name="type" lay-search>
                                <option value="">请选择消息类型</option>
                                <option value="1" {if !empty(input('get.type')) && input('get.type')==1}selected{/if}>
                                    用户端</option>
                                <option value="2" {if !empty(input('get.type')) && input('get.type')==2}selected{/if}>
                                    师傅端</option>
                            </select>
                        </div>
                        <div class="layui-inline">
                            <div class="layui-input-inline ">
                                <input name="title" class="layui-input" type="text" placeholder="联系电话" />
                            </div>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <!-- // 默认搜索 -->
                        <button class="layui-btn icon-btn" lay-filter="formSearch" lay-submit>搜索</button>
                    </div>
                </div>
            </div>
        </div>

        <!-- // 创建数据实例 -->
        <table id="lay-tableList" lay-filter="lay-tableList"></table>
    </div>
</div>
<!-- // 列表工具栏 -->
<script type="text/html" id="tableBar">
    <a class="layui-table-text" data-title="回复消息" data-area="30%,40%" callback="edits" data-url="#adminforms"  lay-event="edit">回复消息</a>
</script>
<script type="text/html" id="adminforms">
    <div class="layui-fluid layui-bg-white">
        <form class="layui-form layui-form-fixed" lay-filter="adminforms">
            <div class="layui-form-item">
            <label class="layui-form-label"><font color="red">* </font>回复内容</label>
            <div class="layui-input-block">
                <input name="reply"  placeholder="请填写回复内容" type="text" class="layui-input" lay-verify="required" />
            </div>
        </div>
        <div class="layui-footer layui-form-item layui-center ">
            <button class="layui-btn" lay-filter="submitPage" lay-submit>提交</button>
            <button class="layui-btn layui-btn-primary" type="button" sa-event="closePageDialog" >取消</button>
        </div>
        </form>
    </div>
</script>
{include file="public/nfooter"}
<script>
    layui.use(['admin', 'layer', 'table', 'form'], function () {

        var admin = layui.admin;
        var layer = layui.layer;
        var table = layui.table;        // 表格
        var form = layui.form;
        admin.callback.edits = function (clickthis, colletction, config) {
            var tableThis = colletction.tableThis;
            // 监听权限提交
            form.on("submit(submitPage)", function (post) {

                // 获取用户id
                var pageThat = layui.$(this);
                pageThat.attr("disabled", true);
                // 开始POST提交数据
                post.field.id = tableThis.data.id;
                layui.$.post("{:url('system/replymessage')}", post.field, function (res) {
                    if (res.code == 200) {
                        layer.msg(res.msg);
                        // 关闭当前窗口
                        table.reload('lay-tableList');
                        layer.close(colletction.index);
                    }
                    else {
                        layer.error(res.msg);
                    }
                }, 'json');

                return false;
            })
        }
        var isTable = table.render({
            elem: "#lay-tableList"
            , url: "{:url()}"
            , page: true
            , size: 'lg'
            , even: true
            , cols: [[
                { type: 'checkbox', width: 60 },
                { field: 'id', align: 'center', sort: true, width: 80, title: 'ID' },
                { field: 'mobile', align: 'center', width: 150, title: '联系电话' },
                { field: 'message', width: 200, align: 'center', title: '消息内容' },
                {
                    align: 'reply', width: 250, title: '回复内容', templet: function (d) {
                        if (d.reply == null || d.reply == '' || d.reply == 'undefined') {
                            return '无';
                        }
                        return d.reply;
                    }
                },
                {
                    field: 'images', width: 200, align: 'center', title: '图片', templet: function (d) {
                        var str = '';
                        $.each(d.images, function (i, obj) {
                            str += '<img lay-image-click="" style="width:50px;" src="' + obj;
                            str += '"/>';
                        });
                        return str;
                    }
                },
                {
                    field: 'messtype', align: 'center', width: 120, templet: function (d) {
                        if (d.type == 1) {
                            switch (d.messtype) {
                                case 1:
                                    return '下单问题';
                                    break;
                                case 2:
                                    return '配送问题';
                                    break;
                                case 3:
                                    return '其它问题';
                                    break;
                                default:
                                    break;
                            }
                        } else if (d.type == 2) {
                            switch (d.messtype) {
                                case 1:
                                    return '接单问题';
                                    break;
                                case 2:
                                    return '配送问题';
                                    break;
                                case 3:
                                    return '其它问题';
                                    break;
                                default:
                                    break;
                            }
                        }
                        return '未知';
                    }, title: '问题类型'
                },
                {
                    field: 'type', align: 'center', width: 120, templet: function (d) {
                        if (d.type == 1) {
                            return '用户端';
                        }
                        if (d.type == 2) {
                            return '师傅端';
                        }
                        return '未知';
                    }, title: '消息类型'
                },
                {
                    field: 'status', align: 'center', width: 120, templet: function (d) {
                        if (d.status == 1) {
                            return '未回复';
                        }
                        if (d.status == 2) {
                            return '已回复';
                        }
                        return '未知';
                    }, title: '是否回复'
                },
                { field: 'created', width: 200, align: 'center', title: '添加时间' },
                { align: 'center', toolbar: '#tableBar', width: 100, title: '回复', templet: '#tableBar' },
            ]]
        });
    });
</script>